package com.flexrrb.core
{

	public class ShortcutKey
	{
		private var _shiftEnabled:Boolean;
		private var _ctrlEnabled:Boolean;
		private var _altEnabled:Boolean;
		private var _enabled:Boolean = true;
		private var _ignoreCase:Boolean;
		private var _charKey:String;
		private var _lowercaseCharCode:int;
		private var _uppercaseCharCode:int;
		private var _functionKeyEnabled:Boolean;
		private var _functionKeyCode:int;

		public function ShortcutKey(charKey:String, shiftEnabled:Boolean = false, ctrlEnabled:Boolean = false, altEnabled:Boolean = false, ignoreCase:Boolean = false, functionKeyEnabled:Boolean = false, functionKeyCode:int = 0, enabled:Boolean = true)
		{
			this.charKey = charKey;
			this.ignoreCase = ignoreCase;
			_shiftEnabled = shiftEnabled;
			_ctrlEnabled = ctrlEnabled;
			_altEnabled = altEnabled;
			_functionKeyEnabled = functionKeyEnabled;
			_functionKeyCode = functionKeyCode;
			_enabled = enabled;
		}

		public function get functionKeyCode():int
		{
			return _functionKeyCode;
		}

		public function set functionKeyCode(value:int):void
		{
			_functionKeyCode = value;
		}

		public function get functionKeyEnabled():Boolean
		{
			return _functionKeyEnabled;
		}

		public function set functionKeyEnabled(value:Boolean):void
		{
			_functionKeyEnabled = value;
		}

		public function get charKey():String
		{
			return _charKey;
		}

		public function set charKey(value:String):void
		{
			if (value != null)
			{
				_charKey = value;
				updateKeyCode();
			}
			else
			{
				throw new Error("Key cannot be null");
			}
		}

		private function updateKeyCode():void
		{
			if (ignoreCase)
			{
				_lowercaseCharCode = charKey.toLowerCase().charCodeAt();
				_uppercaseCharCode = charKey.toUpperCase().charCodeAt();;
			}
			else
			{
				_uppercaseCharCode = _lowercaseCharCode = charKey.charCodeAt();
			}
		}

		public function get ignoreCase():Boolean
		{
			return _ignoreCase;
		}

		public function set ignoreCase(value:Boolean):void
		{
			_ignoreCase = value;
			updateKeyCode();
		}

		public function get enabled():Boolean
		{
			return _enabled;
		}

		public function set enabled(value:Boolean):void
		{
			_enabled = value;
		}

		public function get altEnabled():Boolean
		{
			return _altEnabled;
		}

		public function set altEnabled(value:Boolean):void
		{
			_altEnabled = value;
		}

		public function get ctrlEnabled():Boolean
		{
			return _ctrlEnabled;
		}

		public function set ctrlEnabled(value:Boolean):void
		{
			_ctrlEnabled = value;
		}

		public function get shiftEnabled():Boolean
		{
			return _shiftEnabled;
		}

		public function set shiftEnabled(value:Boolean):void
		{
			_shiftEnabled = value;
		}
	}
}